-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for async insert #66
Conversation
465b1cf has fixed a issue with serializing
This happened because
|
Thanks a lot for this. I've used it to ingest fairly large datasets ~200m+ rows |
that's awesome, thank you! I hope it gets merged soon |
Sorry for the late answer. Async inserts are a nice feature and have become production-ready to have API for them. And suggested PR looks great. However, I have ambivalent feelings about it. It's simply options and can be provided by
Have you tried to use |
Does use clickhouse::{Client, Row};
use serde::Serialize;
#[tokio::main]
async fn main() {
let client = Client::default()
.with_url("http://localhost:8123")
.with_user("user")
.with_password("password")
.with_database("mydb")
.with_option("async_insert", "1")
.with_option("wait_for_async_insert", "1");
#[derive(Debug, Row, Serialize)]
struct MyRow {
user_id: u32,
message: String,
}
let mut insert = client.insert("my_table").unwrap();
insert
.write(&MyRow {
user_id: 2,
message: "I am 2".to_string(),
})
.await
.unwrap();
insert.end().await.unwrap();
} and the query actually performed doesn't seem to contain
While by using my patch: use clickhouse::{AsyncInsertOptions, Client, Row};
use serde::Serialize;
#[tokio::main]
async fn main() {
let client = Client::default()
.with_url("http://localhost:22222")
.with_user("user")
.with_password("password")
.with_database("deploy");
#[derive(Debug, Row, Serialize)]
struct MyRow {
user_id: u32,
message: String,
}
let opts = AsyncInsertOptions::builder()
.async_insert(true)
.wait_for_async_insert(true)
.build();
let mut insert = client.async_insert("my_table", opts).unwrap();
insert
.write(&MyRow {
user_id: 3,
message: "I am 3".to_string(),
})
.await
.unwrap();
insert.end().await.unwrap();
} the performed query does include
Also, I'd prefer not to make async_insert settings configured via There is a conflict in one file, and if there's a chance of getting my patch to be merged I'd be happy to address this conflict :) |
3e0ca8c
to
d92234e
Compare
@loyd Resolved the conflict and it's now ready for review again. Could I get your review and opinion on whether you think this is a right direction? Thanks. |
The async insert feature is already supported. We are currently preparing more examples (see this issue for tracking) covering the most common use cases, and the first one I tried was the Here's a simple example: https://github.com/ClickHouse/clickhouse.rs/blob/2f9c021a60255c91289322cd18183933820620bf/examples/async_insert.rs On the main branch, without this changeset, and with
However, the same code with
Re: the SETTINGS clause in the query:
The settings are passed via the query parameters, and they will not show up in the query_log as part of the SETTINGS clause, as it is not attached there. Essentially, the URL that is used for this request is roughly equivalent to:
However, you can still verify that the async insert works via a different query_log query: SELECT query, query_kind, Settings
FROM system.query_log
WHERE query LIKE '%chrs%'
ORDER BY event_time_microseconds DESC
LIMIT 10
FORMAT Vertical; Which will return the following result:
See that the settings were correctly applied, and there is also an async insert flush event. |
Sorry for closing, we've decided to not provide a dedicated API for async insert params |
Closes #65
This patch adds a support for asynchronous inserts.
In order not to break public interface, a new method named
async_insert
is added toClient
, instead of fixing the existinginsert
method.This is my first patch to this repo, so please let me know if there's anything I can improve to make it more consistent with the existing code base. Thanks!